<template>
  <uni-popup
    style="z-index: 99999999;"
    class="login-popup"
    mode="center"
    id="popupApp"
    mask-background-color="rgba(0,0,0,0.9)"
    ref="popupApp"
    :type="type_status"
    :animation="true"
  >
    <view class="login_container relative" style="background-color: #FFFFFF;padding:50rpx 44rpx 30rpx;border-radius: 20rpx;">
      <view class="content-item">
        <view class="text-000 fs34 bold">提示</view>
        <template>
          <view class="text-000 fs28 mt20 content_detail">{{ content }}</view>
        </template>
      </view>
      <view class="footer1 flex">
        <u-button class="custom-style" text="取消" @click="close" shape="circle"></u-button>
        <u-button @click="confirm" class="custom-style-login" text="确定" shape="circle" color="linear-gradient(to right, #1CD19F, #1FB0AC)"></u-button>
      </view>
    </view>
  </uni-popup>
</template>

<script>
import { openAppSettingPermissions, requestAndroidPermission } from '@/common/index.js'
export default {
  name: 'model',
  props: {
    getUserInfo: {
      type: String,
      default: 'login'
    },
    content: {
      type: String,
      default: '完善信息，可享受更多服务！'
    },
    toUrl: {
      type: String,
      default: ''
    },
    openAppPermission: {
      type: Boolean,
      default: false
    },
    isPush: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      type_status: 'center',
      isChecked: false
    }
  },
  methods: {
    confirm() {
      this.close()
      if (this.isPush) {
        this.openPushPermission()
      }else if (this.openAppPermission && !this.isPush) {
        openAppSettingPermissions()
        this.$emit('toOpenAppPermission')
      } else {
        uni.navigateTo({
          url: this.toUrl || '/subpages/pages/xgmp?isUserInfo=2'
        })
      }
    },
    close() {
      this.$refs.popupApp.close()
    },
    open() {
      console.log('%c [ open ]-70', 'font-size:13px; background:pink; color:#bf2c9f;', 'open')
      this.$refs.popupApp.open()
    },
    wechatLogin() {
      // this.post('api/client/app_wx_Login', {code: '061JxvFa1KatZH0AoUFa1bHyN72JxvFz'}, true).then(res => {
      //   console.log('%c [ res ]-63', 'font-size:13px; background:pink; color:#bf2c9f;', res)
      //   if (res.code == 1) {
      //     // uni.setStorageSync('token', res.data.token)
      //     // uni.setStorageSync('userinfo', res.data.userinfo)
      //     // uni.setStorageSync('mobile', res.data.userinfo.mobile)
      //     // uni.setStorageSync('mobile2', res.data.userinfo.mobile2)
      //   } else {
      //     uni.showToast({
      //       title: res.msg,
      //       icon: "none",
      //       duration: 1000
      //     })
      //   }
      // })
      if (this.getUserInfo === 'login') {
        uni.navigateTo({
          url: '/personal/nativeLogin/index'
        })
      } else if (this.getUserInfo === 'mobile') {
        uni.navigateTo({
          url: '/subpages/pages/xgmp'
        })
      }
      this.close()
    },
    phoneLogin() {
      this.close()
    },
    openPushPermission() { //弹窗按钮绑定方法
      let platform = uni.getSystemInfoSync().platform; //获取安卓还是ios
      if (platform == "ios") { //如果机型是ios，ios由于权限问题，可能需要手动开启
        var app = plus.ios.invoke('UIApplication', 'sharedApplication');
        var setting = plus.ios.invoke('NSURL', 'URLWithString:', 'app-settings:');
        plus.ios.invoke(app, 'openURL:', setting);
        plus.ios.deleteObject(setting);
        plus.ios.deleteObject(app);
      } else if (platform == "android") { //如果机型是安卓
        var main = plus.android.runtimeMainActivity();
        var pkName = main.getPackageName();
        var uid = main.getApplicationInfo().plusGetAttribute("uid");
        var Intent = plus.android.importClass("android.content.Intent");
        var Build = plus.android.importClass("android.os.Build");
        //android 8.0引导
        if (Build.VERSION.SDK_INT >= 26) { //判断安卓系统版本
          var intent = new Intent("android.settings.APP_NOTIFICATION_SETTINGS");
          intent.putExtra("android.provider.extra.APP_PACKAGE", pkName);
        } else if (Build.VERSION.SDK_INT >= 21) { //判断安卓系统版本
          //android 5.0-7.0
          var intent = new Intent("android.settings.APP_NOTIFICATION_SETTINGS");
          intent.putExtra("app_package", pkName);
          intent.putExtra("app_uid", uid);
        } else {
          //(<21)其他--跳转到该应用管理的详情页
          intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
          var uri = Uri.fromParts(
            "package",
            mainActivity.getPackageName(),
            null
          );
          intent.setData(uri);
        }
        // 跳转到该应用的系统通知设置页
        main.startActivity(intent);
      }
    }
  },
}
</script>
<style lang="scss">
.footer {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid #f4f4f4;
  margin-top: 30rpx;
  padding-bottom: 20rpx;

  button {
    margin: 0 auto;
    width: 100%;
    background-color: #19be6b;
    // width: 200upx;
    border-radius: 10upx;
    font-size: $uni-font-size-sm;
    // padding: 22upx 34upx;
    height: 80upx;
    font-size: 30rpx;
    line-height: 80upx !important;
    // line-height: 1;
    color: #ffffff;
  }

  button:after {
    border: 0;
  }
}
.login_container {
  width: 600rpx !important;
  margin: 0 auto;
  border-radius: 20rpx;
  // background: url("@/static/login/login_bg.png") no-repeat;
  // background-size: cover;
  // background-size: 100% 100%;
  padding-bottom: 60rpx !important;
  .footer1 {
    margin-top: 60rpx;
  }
}
.content-item {
  margin: 0 0 44rpx;
  text-align: center;
  line-height: 42rpx;
  color: #000;
  font-size: 36rpx;
  .content_detail {
    padding: 0 50rpx;
  }
}
.custom-style {
  width: 400rpx;
  height: 80rpx;
  line-height: 80rpx;
  color: #666;
  border-radius: 80rpx;
  border: 1px solid #d9d9d9;
  background-color: #d9d9d9;
  margin-right: 30rpx;
}
.custom-style-login {
  width: 400rpx;
  height: 80rpx;
  line-height: 80rpx;
}
.login-popup /deep/ .uni-mask--hook {
  background-color: rgba(0, 0, 0, 0.5) !important;
}
.user_agreement_container /deep/ .private {
  margin-left: 40rpx;
}
.close_icon {
  position: absolute;
  top: 26rpx;
  right: 26rpx;
  z-index: 1;
}
</style>